package com.cup.jpa.security.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import com.cup.common.response.ResponseData;

@Component
public class AjaxAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
    	ResponseData<String> responseBody = new ResponseData<>();

        responseBody.setMsg("Need Authorities!");
        responseBody.init("300", "Need Authorities!");

        httpServletResponse.getWriter().write(responseBody.toString());
    }
}
